<template>
    <div class="page rdsp-fix-botttom-page" data-page="studyRecord">
        <div class="link-page-nav">
            <a href="#" class="link" @click="$root.backToTab">
                <i class="iconfont icon-zuo"></i>
            </a>
        </div>
        <div class="link-page-top" style="padding-bottom: 17px;">
            <div class="link-page-title">我的学习记录</div>
        </div>
        <div class="page-content infinite-scroll-content ptr-content" style="padding-bottom: 25px;"
             @infinite="loadMoreStudyList" @ptr:refresh="refreshMessage"
            data-infinite-distance="50">
            <div class="ptr-preloader">
                <div class="preloader color-multi"></div>
                <div class="ptr-arrow"></div>
            </div>
            <div>
                <div class="study-record-block">
                    <div class="left-title fl" style="margin-left: 21px;"></span>统计日期</div>
                    <div class="right-con  has-arrow">
                        <div id="study_record_{{getNewId}}" @click="selectDate" class="right-select">2019年09月</div>
                        <i class="iconfont icon-zuo"></i>
                    </div>
                </div>
            </div>
            <div style="margin:10px 20px">
                <p class="study-title">个人学习总时长</p>
                <div class="study-title-bg">
                    <span class="study-total" id="study_record_total_{{getNewId}}">11天11小时11分钟</span>
                </div>
            </div>
            <div style="margin:10px 20px">
                <p class="study-title">个人学习明细</p>
                <div class="list media-list unitStat-list-dslist no-hairline-bottom search-list searchbar-found">
                    <ul id="study-list-{{getNewId}}">

                    </ul>
                    </ul>
                    <div id="study_preloader_{{getNewId}}" class="preloader infinite-scroll-preloader"></div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    return {
        mounted() {
            var self = this;
            var $ = self.$;
        },
        data: function () {
            return {
                getNewId: (new Date()).getTime(),
                pageIndex: 0,
                pageSize: 10,
                selectOptionIndex: "0",
                allowInfinite:true,
            }
        },
        methods: {
            backToRefresh:function(){
                var self = this;
                self.pageIndex = 0;
                self.getPersonalTime();
            },
            refreshMessage:function(e, done){
                var self = this;
                if (done && e) {
                    jQuery(".ptr-preloader").show();
                    var self = this;
                    self.pageIndex = 0;
                    var $ = self.$$;
                    setTimeout(function () {
                        self.getPersonalTime();
                        done();
                        jQuery(".ptr-preloader").hide();
                    }, 1000);
                }
                
            },
            selectDate: function () {
                var self = this;
                let date = common.getTimeArray(1);
                selectOptionFn(date, function (data) {
                    if (self.selectOptionIndex != data.index) {
                        var timeArr = data.name;
                        jQuery("#study_record_" + self.getNewId).html(timeArr);
                        jQuery("#study_record_" + self.getNewId).addClass('select-active');
                        self.selectOptionIndex = data.index;
                    } else {
                        self.selectOptionIndex = 0;
                        jQuery("#study_record_" + self.getNewId).html(moment().format('YYYY年MMM'));
                        if(jQuery('.rdsp-option-list').eq(0).hasClass('active')){
                            jQuery('.rdsp-option-list').eq(0).removeClass('active')
                        }
                        jQuery("#study_record_" + self.getNewId).removeClass('select-active');
                    }
                    $("#study-list-" + self.getNewId).empty();
                    self.getPersonalTime();
                }, self.selectOptionIndex);
            },
            //个人学习总时长 & 个人学习明细
            getPersonalTime: function () {
                var self = this;
                var month = jQuery("#study_record_" + self.getNewId).html();
                var startTime = moment(month, 'YYYY年MM').startOf('month').format("YYYY-MM-DD HH:mm:ss")
                var endTime = moment(month, 'YYYY年MM').endOf('month').format("YYYY-MM-DD HH:mm:ss")
                Dao.selectPersonLearningTime({
                    queryType: 1,
                    pageIndex: self.pageIndex,
                    pageSize: self.pageSize,
                    startTimeStr: startTime,
                    endTimeStr: endTime,
                    userAccount: userInfor.userAccount
                }, function (data) {
                    if (!data) {
                        jQuery("#study_preloader_"+ self.getNewId).hide();
                        return;
                    }
                    self.allowInfinite = true;
                    jQuery("#study_record_total_" + self.getNewId).html(data.totalTimeStr||'无');

                    if (self.pageIndex == 0) {
                        $("#study-list-" + self.getNewId).empty();
                    }

                    var datalist = data.list;
                    if (!datalist || datalist.length < 1) {
                        jQuery("#study_preloader_"+ self.getNewId).hide();
                        if (self.pageIndex == 0) { //暂无数据
                            $("#study-list-" + self.getNewId).empty();
                            $("#study-list-" + self.getNewId).append(`<div class="no-data-img"><img src="` + listNoDataPic() + `"/></div>`);
                        }
                        return;
                    }
                    if (datalist.length > 0) {
                        if(self.pageIndex == 0 && datalist.length < self.pageSize){
                            jQuery("#study_preloader_"+ self.getNewId).hide();
                        }else{
                            jQuery("#study_preloader_"+ self.getNewId).show();
                        }
                        for (var i = 0; i < datalist.length; i++) {
                            var m = datalist[i];
                            var html = `
                                <li id="study_record_`+ m.id + `" data="` + m.id + `">
                                    <a href="#" class="item-link item-content" data-view=".view-main">
                                        <div class="decter-pic-con" id="dectorImg-`+m.id+`">
                                 
                                        </div>
                                        <div class="item-inner" style="padding: 0;margin-top:10px;">
                                        <div class="item-title-row" style="padding-right: 0;">
                                            <div title="`+ m.title + `" class="item-title decter-name-con">
                                            `+ m.title + `
                                            </div>
                                        </div>
                                        <div class="item-subtitle decter-mesage">` + `累计学习` + m.userLearningTimeStr + `</div>
                                        </div>
                                    </a>
                                </li>
                            `;
                            jQuery("#study-list-" + self.getNewId).append(html);
                            showImage(jQuery("#dectorImg-"+m.id),m.coverUrl|| staticPath + "img/default/emptyStudyImg.png",1);//必须在append 后
                            jQuery("#study_record_" + m.id).off().on('click', { 'data': m.id,'isDelete':m.isDelete }, function (e) {
                                if(e.data.isDelete == 1){
                                    app.methods.showToastCenter('该文章已删除！');
                                    return;
                                }
                                app.router.navigate("/studyDetail/" + e.data.data + "/");
                            });
                        }
                    }
                });
            },
            loadMoreStudyList:function(){
                var self = this;
                var $ = self.$$;
                if (self.allowInfinite){
                    self.allowInfinite = false;
                    setTimeout(function () {
                        self.pageIndex++;
                        self.getPersonalTime();
                    }, 1000);
                }
            },
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                var $ = self.$;
                jQuery("#study_record_" + self.getNewId).html(moment().format('YYYY年MMM'));
                jQuery("#study_preloader_"+ self.getNewId).show();
                jQuery("#study_record_" + self.getNewId).addClass('select-active');
                self.getPersonalTime();
            },
        }
    }
</script>
<style>
    .right-select {
        text-align: right;
        padding-right: 25px;
        color: rgba(0, 0, 0, 0.7);
    }

    .study-record-block {
        margin: 20px 0 10px 0;
    }

    .study-record-block .left-title {
        margin-left: 20px;
        color: #333333;
        vertical-align: top;
        font-size: 18px;
        font-weight: 600;
    }

    .study-record-block .right-con.has-arrow .icon-zuo {
        position: absolute;
        top: 18px;
        right: 9px;
        font-size: 14px;
        transform: rotate(180deg);
        -webkit-transform: rotate(180deg);
        color: #999;
    }

    .unitStat-list-dslist li {
        border-bottom: 1px solid rgba(51, 51, 51, 0.05);
        margin-bottom: 20px;
    }

    .media-list li {
        border: 1px solid rgba(225, 225, 225, 0.9);
        box-shadow: 0px 1px 10px 0px rgba(53, 106, 122, 0.5);
        border-radius: 6px;
        margin-bottom: 20px;
    }

    .item-link.item-content {
        padding-bottom: 10px;
        width: 100%;
    }

    .decter-name-con {
        width: 95%;
        white-space: initial !important;
        display: inline-block;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        font-size: 16px;
        height: 60px;
        font-weight: bold;
    }

    .decter-name {
        font-size: 16px !important;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }

    .study-title {
        margin-top: 30px;
        margin-bottom: 20px;
        font-size: 18px;
        font-weight: 600;
    }

    .study-total {
        margin: auto;
        vertical-align: middle;
        height: 100%;
        line-height: 120px;
        font-size: 34px;
        font-weight: 600;
        color: #2471CA
    }

    .study-pic {
        width: 60px;
        height: 60px;
        background-position: center;
        background-size: cover;
        background-repeat: no-repeat;
    }

    .decter-pic-con {
        width: 60px;
        height: 60px;
        background: #e7e7e7;
        border: 1px solid #e1e1e1;
        margin-right: 15px;
        margin-top: 10px;
    }

    .image-item {
        width: 60px;
        height: 60px;
    }

    .searchbar-found {
        margin: 20px 0;
    }

    .decter-mesage {
        font-size: 12px;
        color: #999999
    }

    .study-title-bg {
        background-color: #F1F1F1;
        height: 120px;
        text-align: center;
        border:1px #E1E1E1;
    }

    .item-inner {
        padding: 0 !important;
        margin-top: 10px !important;
    }

    .item-title-row {
        padding-right: 0 !important;
    }

    .item-inner:after{
        height: 0px!important;
    }
    .md .list ul:before{
        height: 0px;
    }
    .decter-name-con{
        height: 100%;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2; 
        overflow: hidden;
    }
</style>